package com.firefly.admin.tripartite.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.firefly.admin.common.annotations.annotation.OperationLog;
import com.firefly.admin.common.enums.OperationModuleEnum;
import com.firefly.admin.common.enums.OperationTypeEnum;
import com.firefly.admin.common.vo.Result;
import com.firefly.admin.tripartite.entity.FyTripartiteWechatMerchant;
import com.firefly.admin.tripartite.service.FyTripartiteWechatMerchantService;
import com.firefly.admin.tripartite.vo.WechatMerchantQueryVo;
import com.firefly.admin.tripartite.vo.WechatMerchantStatusUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "第三方微信商户接口API")
@RestController
@RequestMapping("/tripartite/wechat/merchant")
public class FyTripartiteWechatMerchantController {
    @Autowired
    private FyTripartiteWechatMerchantService fyTripartiteWechatMerchantService;

    /**
     * 分页查询第三方微信商户接口
     *
     * @param wechatMerchantQueryVo 分页查询参数
     * @return 分页列表
     */
    @ApiOperation(value = "分页查询第三方微信商户接口", notes = "分页查询第三方微信商户接口", httpMethod = "GET")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:merchant')")
    @GetMapping("/list")
    public Result<Page<FyTripartiteWechatMerchant>> getWechatMerchantList(WechatMerchantQueryVo wechatMerchantQueryVo) {
        return fyTripartiteWechatMerchantService.getWechatMerchantList(wechatMerchantQueryVo);
    }

    /**
     * 第三方微信商户信息新增接口
     *
     * @param fyTripartiteWechatMerchant 微信商户信息
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信商户信息新增接口", notes = "第三方微信商户信息新增接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_MERCHANT_CONFIG, operateDesc = "第三方微信商户新增")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:merchant:add')")
    @PostMapping("/add")
    public Result<FyTripartiteWechatMerchant> add(@RequestBody FyTripartiteWechatMerchant fyTripartiteWechatMerchant) {
        return fyTripartiteWechatMerchantService.add(fyTripartiteWechatMerchant);
    }

    /**
     * 第三方微信商户信息编辑接口
     *
     * @param fyTripartiteWechatMerchant 微信商户信息
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信商户信息编辑接口", notes = "第三方微信商户信息编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_MERCHANT_CONFIG, operateDesc = "第三方微信商户编辑")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:merchant:update')")
    @PostMapping("/update")
    public Result<FyTripartiteWechatMerchant> update(@RequestBody FyTripartiteWechatMerchant fyTripartiteWechatMerchant) {
        return fyTripartiteWechatMerchantService.update(fyTripartiteWechatMerchant);
    }

    /**
     * 第三方微信商户状态编辑接口
     *
     * @param wechatMerchantStatusUpdateVo 状态信息
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信商户状态编辑接口", notes = "第三方微信商户状态编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_MERCHANT_CONFIG, operateDesc = "第三方微信商户修改状态")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:merchant:update:status')")
    @PostMapping("/update/status")
    public Result<FyTripartiteWechatMerchant> updateStatus(@RequestBody WechatMerchantStatusUpdateVo wechatMerchantStatusUpdateVo) {
        return fyTripartiteWechatMerchantService.updateStatus(wechatMerchantStatusUpdateVo);
    }

    /**
     * 第三方微信商户信息删除接口
     *
     * @param merchantConfigId 微信商户ID
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信商户信息删除接口", notes = "第三方微信商户信息删除接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_MERCHANT_CONFIG, operateDesc = "第三方微信商户删除")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:merchant:delete')")
    @PostMapping("/delete")
    public Result<String> delete(Long merchantConfigId) {
        return fyTripartiteWechatMerchantService.delete(merchantConfigId);
    }

    /**
     * 第三方微信商户号校验接口
     *
     * @param merchantId       微信商户号
     * @param merchantConfigId 微信商户配置ID
     * @return 校验结果
     */
    @ApiOperation(value = "第三方微信商户号校验接口", notes = "第三方微信商户号校验接口", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "merchantId", required = true, value = "微信商户号", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "merchantConfigId", required = true, value = "微信商户配置ID", paramType = "query", dataType = "Long")
    })
    @GetMapping("/merchant/id/check")
    public Result<String> merchantIdCheck(String merchantId, Long merchantConfigId) {
        return fyTripartiteWechatMerchantService.merchantIdCheck(merchantId, merchantConfigId);
    }

    /**
     * 查询可用的第三方微信商户接口
     *
     * @return 微信商户列表
     */
    @ApiOperation(value = "查询可用的第三方微信商户接口", notes = "查询可用的第三方微信商户接口", httpMethod = "GET")
    @GetMapping("/usable/list")
    public Result<List<FyTripartiteWechatMerchant>> getUsableWechatMerchantList() {
        return fyTripartiteWechatMerchantService.getUsableWechatMerchantList();
    }

}
